package com.ph.demo.cas;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceDemo {

    static AtomicReference<String> atomicReference = new AtomicReference<String>("abc");

    public static void main(String[] args) {

        for (int i = 0; i <10 ; i++) {

            final  int num =i;

            new Thread(){

                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    if(atomicReference.compareAndSet("abc","def")){

                        System.out.println(Thread.currentThread().getId()+"修改成功");
                    }else{
                        System.out.println(Thread.currentThread().getId() + "修改失败");
                    }
                }
            }.start();
        }

    }



}
